package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RiskyWebsites;
import com.ruoyi.system.service.IRiskyWebsitesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险网管理Controller
 *
 * @author ruoyi
 * @date 2022-09-23
 */
@Controller
@RequestMapping("/system/websites")
public class RiskyWebsitesController extends BaseController {
    private String prefix = "system/websites";

    @Autowired
    private IRiskyWebsitesService riskyWebsitesService;

    @RequiresPermissions("system:websites:view")
    @GetMapping()
    public String websites() {
        return prefix + "/websites";
    }

    /**
     * 查询风险网管理列表
     */
//    @RequiresPermissions("system:websites:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskyWebsites riskyWebsites) {
        startPage();
        List<RiskyWebsites> list = riskyWebsitesService.selectRiskyWebsitesList(riskyWebsites);
        return getDataTable(list);
    }

    /**
     * 导出风险网管理列表
     */
    @RequiresPermissions("system:websites:export")
    @Log(title = "风险网管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskyWebsites riskyWebsites) {
        List<RiskyWebsites> list = riskyWebsitesService.selectRiskyWebsitesList(riskyWebsites);
        ExcelUtil<RiskyWebsites> util = new ExcelUtil<RiskyWebsites>(RiskyWebsites.class);
        return util.exportExcel(list, "风险网管理数据");
    }

    /**
     * 新增风险网管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存风险网管理
     */
    @RequiresPermissions("system:websites:add")
    @Log(title = "风险网管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskyWebsites riskyWebsites) {
        return toAjax(riskyWebsitesService.insertRiskyWebsites(riskyWebsites));
    }

    /**
     * 修改风险网管理
     */
    @RequiresPermissions("system:websites:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        RiskyWebsites riskyWebsites = riskyWebsitesService.selectRiskyWebsitesById(id);
        mmap.put("riskyWebsites", riskyWebsites);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险网管理
     */
    @RequiresPermissions("system:websites:edit")
    @Log(title = "风险网管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskyWebsites riskyWebsites) {
        return toAjax(riskyWebsitesService.updateRiskyWebsites(riskyWebsites));
    }

    /**
     * 删除风险网管理
     */
    @RequiresPermissions("system:websites:remove")
    @Log(title = "风险网管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(riskyWebsitesService.deleteRiskyWebsitesByIds(ids));
    }

    /**
     * 移动端添加方法
     *
     * @param riskyWebsites 对象
     * @return
     */
    @PostMapping("/myadd")
    @ResponseBody
    public AjaxResult myadd(RiskyWebsites riskyWebsites) {
        riskyWebsitesService.insertRiskyWebsites(riskyWebsites);
        return success();

    }

    @PostMapping("/mygetitem")
    @ResponseBody
    public AjaxResult getitem(@RequestParam("site") String site) {
        RiskyWebsites riskyWebsites=new RiskyWebsites();
        riskyWebsites.setSite(site);
        riskyWebsitesService.selectRiskyWebsitesList(riskyWebsites);
        return success();
    }
}
